#include <bits/stdc++.h>

using namespace std;
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3f;

void solve()
{
	int a, b, x, y;
	cin >> a >> b >> x >> y;
	if (a > b)
	{
		if (b == a - 1 && a & 1) cout << y << endl;
		else cout << -1 << endl;
	}
	else if (a == b) cout << 0 << endl;
	else
	{
		if (x <= y) cout << (b - a) * x << endl;
		else
		{
			if (a & 1)
			{
				int ans = 0, cnt = 0;
				while (a != b)
				{
					if (cnt == 0) ans += x;
					else ans += y;
					cnt ^= 1;
					a++;
				}
				cout << ans << endl;
			}
			else
			{
				int ans = 0, cnt = 0;
				while (a != b)
				{
					if (cnt == 0) ans += y;
					else ans += x;
					cnt ^= 1;
					a++;
				}
				cout << ans << endl;
			}

		}
	}
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int _ = 1;
	cin >> _;
	while (_--)
	{
		solve();
	}
	return 0;
}